#-*- encoding=utf-8 -*-
'''
Created on 2014. 2. 11.

@author: 주영
'''

from collections import MutableMapping;

class MapBase(MutableMapping):
	'''
	Abstract base class for map.
	'''
	
	class _Item:
		__slot__ = 'key', '_value_';
		
	def __init__(self, k, v):
		self._key = k;
		self._value = v;
		
		
	def __eq__(self, other):
		return self._key == other._key;
	
	def __ne__(self, other):
		return not (self == other );
	
	def __lt__ (self, other ):
		return self._key < other._key;
	
	
	
class UnsortedTableMap(MapBase):
	'''
	Map implementation using an unordered list
	'''
	
	def __init__(self):
		self._table = [];
		
	def __getitem__(self, k):
		for item in self._table:
			if k == item._key:
				return item._value;
		raise KeyError('Key Error: ' + repr(k));
	
	def __setitem__(self, k, v):
		for item in self._table:
			if k == item._key:
				item._value = v;
				return 
		
		self._table.append(self._Item(k,v));
		
			
	def __delitem__(self, k):
		for i in range(len(self._table)):
			if (self._table[i]._key == k):
				self._table.pop(i);
				return;
		raise KeyError('KeyError: '+repr(k));
	
	def __len__(self):
		return len(self._table);
	